package com.first.xiinn.action.web;

import java.io.File;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.first.core.web.Constants;
import com.first.core.web.action.BaseAction;
import com.first.xiinn.model.BookManager;
import com.first.xiinn.model.User;
import com.first.xiinn.service.BookCatalogService;
import com.first.xiinn.service.BookService;
import com.first.xiinn.service.UserService;
import com.opensymphony.xwork2.ActionContext;

public class BookWebAction extends BaseAction {
	@Resource
	private BookService bookService;
	@Resource
	private BookCatalogService catalogService;
	@Resource
	private UserService userService;
	private String id;
	private String ids;
	private File filePto;
	private String filePtoFileName;
	private File fileElectronic;
	private String fileElectronicFileName;
	private String bookid;

	public String getBookid() {
		return bookid;
	}

	public void setBookid(String bookid) {
		this.bookid = bookid;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getIds() {
		return ids;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}


	public File getFilePto() {
		return filePto;
	}

	public void setFilePto(File filePto) {
		this.filePto = filePto;
	}

	public String getFilePtoFileName() {
		return filePtoFileName;
	}

	public void setFilePtoFileName(String filePtoFileName) {
		this.filePtoFileName = filePtoFileName;
	}

	public File getFileElectronic() {
		return fileElectronic;
	}

	public void setFileElectronic(File fileElectronic) {
		this.fileElectronic = fileElectronic;
	}

	public String getFileElectronicFileName() {
		return fileElectronicFileName;
	}

	public void setFileElectronicFileName(String fileElectronicFileName) {
		this.fileElectronicFileName = fileElectronicFileName;
	}

	public static String getUserMenuDoc() {
		return USER_MENU_DOC;
	}

	private static final String USER_MENU_DOC = "_USER_MENU_DOC";

	public String book() {
		BookManager book = this.bookService
				.get(bookid);
		if (book.getAuthor() != null && !"".equals(book.getAuthor())) {
			User user = this.userService.get(book.getAuthor());
			book.setAuthorName(user.getName());
		}
		setActionContextValue("book", book);
		List<?> list = this.catalogService.search(book.getId());
		setActionContextValue("cataloglist", list);
		
		ActionContext ac = ActionContext.getContext();
		@SuppressWarnings("unchecked")
		Map<String, User> session = ac.getSession();
		User loginWebUser = null;
		if(session!=null){
			loginWebUser =  (User)session.get(Constants.USER_SESSION_KEY);
		}
		setActionContextValue("loginWebUser", loginWebUser);
		return "success";
	}
}
